package com.kakavr.result;

import java.util.Map;

import com.google.common.collect.Maps;
import com.kakavr.result.constant.MsgConstants;

/**
 * 返回消息类
 * 
 * @author gang.yang
 */
public class MsgResult {
	public static Map<String, Object> infoResult(int code, String message, Object map) {
		Map<String, Object> returnMap = Maps.newHashMap();
		returnMap.put("code", code);
		returnMap.put("msg", message);
		returnMap.put("data", map);
		return returnMap;
	}

	public static Object getData(Map<String, Object> map) {
		return map.get("data");
	}

	public static Object getCode(Map<String, Object> map) {
		return map.get("code");
	}

	public static Map<String, Object> okResult() {
		return infoResult(MsgConstants.MSG_CODE_SUCCESS, MsgConstants.MSG_CONTENT_SUCCESS, "");
	}

	public static Map<String, Object> errorResult() {
		return infoResult(MsgConstants.MSG_CODE_ERROR, MsgConstants.MSG_CONTENT_ERROR, "");
	}

	public static Map<String, Object> exceptionResult() {
		return infoResult(MsgConstants.MSG_CODE_EXCEPTION, MsgConstants.MSG_CONTENT_EXCEPTION, "");
	}

	public static Map<String, Object> okResultData(Object map) {
		return infoResult(MsgConstants.MSG_CODE_SUCCESS, MsgConstants.MSG_CONTENT_SUCCESS, map);
	}

	public static Map<String, Object> errorResult(int code, String message) {
		return infoResult(code, message, "");
	}
}
